﻿using System;

using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;

namespace AMC.SubstitutionCache.Drivers
{
    public abstract class EditorTemplateSubstitutionDriver<TPart> : SubstitutionDriver<TPart>
        where TPart : ContentPart, new()
    {
        protected EditorTemplateSubstitutionDriver()
        {
            AddHandledShape(() => CreateHandledShape(EditorTemplateShapeType, GroupId, true, EditorTemplateShapeLocator));
        }

        protected abstract string TemplateName { get; }

        protected virtual string EditorTemplateShapeType { get { return GetEditorTemplateShapeType(TemplateName); } }

        protected override Action<BuildShapeContext, dynamic> ShapeConfig
        {
            get
            {
                return (context, shape) =>
                {
                    shape.EditorTemplateShapeType = EditorTemplateShapeType;
                };
            }
        }

        protected ContentShapeResult PlaceholderShape(TPart part, dynamic shapeHelper, string shapeType)
        {
            return PlaceholderShape(part, shapeHelper, shapeType, "EditorTemplate", TemplateName, string.Empty);
        }
    }
}